<?php
namespace app\admin\controller;

use think\Cache;
use think\Db;

class Index extends Base{

    /**
     * @description : [后台首页]
     * @author : [zhuangze]
     * @return mixed
     */
    public function index(){
        return $this->fetch();
    }

    //配置列表
    public function config(){
        $list = Db::table('bze_config')
            ->where(['is_show'=>1,'location'=>0])
            ->order('sort')
            ->select();
        return $this->fetch('', [
            'list'  =>  $list,
            'list2'  =>  json_encode($list),
        ]);
    }

    //保存配置
    public function saveConfig(){
        $postData = input('post.');
        $id = $postData['id'];
        $config_value = $postData['config_value'];
        $res = Db::table('bze_config')
            ->where(['id'=>$id])
            ->update(['config_value'=>$config_value]);
        if(false!==$res){
            return show(0, '更新成功');
        }else{
            return show(0, '更新失败');
        }
    }

    /**
     * @description : [清空缓存]
     * @return array
     */
    public function refreshCache(){
        Cache::clear();
        return show(0, '刷新成功');
    }

}
